<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Model;
use \think\Session;
use think\Request;

class Login extends Controller
{

    public function login()
    {
    	if (request()->isPost()) 
    	{
            // 加载用户model
    		$adminUserModel = model('adminUser');

    		$verify = input('post.verify');

    		$account = input('post.account');

    		$password = md5(input('post.password'));

    		$adminUserInfo = $adminUserModel->selectOne($account);

    		if ($adminUserInfo) 
    		{
    			if ($password == $adminUserInfo['password'])
    			{
                    // 将userID存入session
    				Session::set('userId',$adminUserInfo['userId']);
                    //将用户名存入session
    				Session::set('account',$adminUserInfo['account']);

    				$this->success('登录成功','index/index');
    			}
    			else
    			{
    				$this->error('账号或密码错误','login/login');
    			}
    		}
    		else
    		{
    			$this->error('账号或密码错误','login/login');
    		}
    	}
    	else
    	{
    		return $this->fetch('login');
    	}
    }

    /**
      退出登录
    */
    public function quitLogin()
    {
        session('userId',null);
        return $this->fetch('login');
    }
}